home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / COMPRESS.AML < prev    next >
Text File  |  1996-07-17  |  2KB  |  105 lines

  1. //--------------------------------------------------------------------
  2. // COMPRESS.AML
  3. // Find Occurrences via Folding, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Compress.dox for user help)
  6. //
  7. // This macro hides all lines (via folding) in the current edit window,
  8. // where a search string is not found.
  9. //
  10. // Usage:
  11. //
  12. // Select this macro from the Macro List (on the Macro menu), or run it
  13. // from the macro picklist <shift f12>.
  14. //--------------------------------------------------------------------
  15.  
  16. include bootpath "define.aml"
  17.  
  18. // test for edit windows
  19. if not wintype? "edit" then
  20.   msgbox "Edit windows only!"
  21.   return
  22. end
  23.  
  24. // prompt the user for the search string in multi-string format
  25. string_and_opt = ask "[string/birswx] Display occurrences of"  "_find"
  26. if not string_and_opt then
  27.   return
  28. end
  29.  
  30. // add the search string to _find history buffer
  31. addhistory "_find" string_and_opt
  32.  
  33. variable search_string, options, o
  34.  
  35. // parse the search multi-string
  36. n = splitstr '' string_and_opt
  37.              ref search_string  ref options  ref o
  38.  
  39. // initialize search options
  40. if n >= 2 then
  41.   if n > 2 then
  42.     options = o
  43.   end
  44. else
  45.   options = _SearchOpt
  46. end
  47. if pos 'g' options then
  48.   options = sub 'g' '' options
  49. end
  50. options = options + '*'
  51.  
  52. // initialize last line number and fold-count
  53. lastline = 1
  54. count = 0
  55.  
  56. // group undo, and use a temporary mark
  57. undobegin
  58. oldmark = usemark 'T'
  59.  
  60. // save cursor position and move the cursor to the top of the file
  61. pushcursor
  62. gotopos 1 1
  63.  
  64. // do for all lines where the search string is found
  65. while find  search_string options  do
  66.   thisline = getrow
  67.  
  68.   // fold the lines from the last line to the current line
  69.   if thisline > lastline then
  70.     markline lastline thisline - 1
  71.     foldblock
  72.     count = count + 1
  73.   end
  74.  
  75.   lastline = thisline
  76.   col MAX_COL
  77. end
  78. breakoff
  79.  
  80. // fold the last block, if applicable
  81. if count then
  82.   if getlines > lastline then
  83.     markline lastline (getlines)
  84.     foldblock
  85.   end
  86. end
  87.  
  88. // restore the cursor position
  89. popcursor
  90.  
  91. // destroy the temp mark and use the default mark
  92. destroymark
  93. usemark oldmark
  94.  
  95. // end of undo group
  96. undoend
  97.  
  98. // display the number of lines where the search string is found
  99. display
  100. if count then
  101.   say count + " lines found"
  102. else
  103.   say "'" + string_and_opt + "'" + " not found" 'b'
  104. end
  105.